package com.example.seekbars;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

public class MainActivity extends Activity {

	SeekBar seekbar; //SeekBar variable
	TextView value; //TextView variable
	ProgressBar progressbar; //ProgressBar variable

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		seekbar = (SeekBar) findViewById(R.id.seekBar1); //link "seekbar" with "seekBar1" from xml
		value = (TextView) findViewById(R.id.textView1); //link "value" with "textView1" from xml
		progressbar = (ProgressBar) findViewById(R.id.progressBar1); //link "progress" with "progressBar1" from xml

		seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { //link "seekbar" with seek bar change listener
			public void onProgressChanged(SeekBar seekBar, int progress,
					boolean fromUser) {
				// TODO Auto-generated method stub
				value.setText("SeekBar at " + progress + "%"); //update "progress" value and pass it to textview
				progressbar.setProgress(progress); // also update "progress" value and pass it to progress bar
			}

			public void onStartTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub
			}

			public void onStopTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub
			}
		});

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}
}
